package name.fowler.refactoring.simplestore;

public class DefaultFrequentPointCalculator implements FrequentPointCalculator  {

	 /* counting frequent points by rented days and movie type
	 * 
	 * @param frequentRenterPoints
	 * @param rental
	 * @return
	 */
	@Override
	public int getFrequentPoints(Customer customer) {
		final int regularPoints = 1;
		final int bonusTresholdDaysRented = 1;
		final int bonusFrequentPoint = 1;
		int result = 0;
		for (Rental rental : customer.getMovieRenatals()) {
			final boolean isMoreThanTreshold = rental.getDaysRented() > bonusTresholdDaysRented;
			final boolean isNewRelease = rental.getMovie().getPriceCode() == PriceCodes.NewRelease;
			int bonus = (isNewRelease && isMoreThanTreshold) ? bonusFrequentPoint : 0;
			result += regularPoints + bonus;
		}
		return result;
	}
}
